﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Adams.Public.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("Home", "", new { controller = "Home", action = "Index" }, new string[] { "Adams.Public.Web.Controllers" });

            routes.MapRoute("Donate", "Donate/{action}", new { controller = "Donate", action = "Index" }, new string[] { "Adams.Public.Web.Controllers" });

            routes.MapRoute("Search", "Search", new { controller = "Search", action = "Index" }, new string[] { "Adams.Public.Web.Controllers" });
            routes.MapRoute("Sitemap", "Sitemap", new { controller = "Sitemap", action = "Index" }, new string[] { "Adams.Public.Web.Controllers" });

            routes.MapRoute("Login", "Login", new { controller = "Security", action = "Login" });
            routes.MapRoute("Logout", "Logout", new { controller = "Security", action = "Logout" });
            routes.MapRoute("Signup", "Signup", new { controller = "Security", action = "Signup" });
            routes.MapRoute("Security", "Security/{action}", new { controller = "Security", action = "" });

            routes.MapRoute("DailyPrayers", "Prayers/Daily/{location}/{month}", new { controller = "DailyPrayers", action = "Index", location = "", month = "" });
            routes.MapRoute("JummahPrayers", "Prayers/Jummah", new { controller = "JummahPrayers", action = "Index" });
            routes.MapRoute("JummahPrayersLocation", "Prayers/Jummah/{location}", new { controller = "JummahPrayers", action = "Location", location = "" });
            routes.MapRoute("TarawehPrayers", "Prayers/Taraweh", new { controller = "TarawehPrayers", action = "Index" });
            routes.MapRoute("TarawehPrayersLocation", "Prayers/Taraweh/{location}", new { controller = "TarawehPrayers", action = "Location", location = "" });
            routes.MapRoute("EidPrayers", "Prayers/Eid", new { controller = "EidPrayers", action = "Index" });
            routes.MapRoute("EidPrayersLocation", "Prayers/Eid/{location}", new { controller = "EidPrayers", action = "Location", location = "" });

            routes.MapRoute("Event", "Events/{id}", new { controller = "Events", action = "Event", id = "" }, new { id = @"\d+" });
            routes.MapRoute("Events", "Events/{action}", new { controller = "Events", action = "Index" });

            routes.MapRoute("Announcement", "Announcements/{id}", new { controller = "Announcements", action = "Announcement", id = "" }, new { id = @"\d+" });
            routes.MapRoute("Announcements", "Announcements/{action}", new { controller = "Announcements", action = "Index" });

            routes.MapRoute("PressRelease", "PressReleases/{id}", new { controller = "PressReleases", action = "PressRelease", id = "" }, new { id = @"\d+" });
            routes.MapRoute("PressReleases", "PressReleases/{action}", new { controller = "PressReleases", action = "Index" });

            routes.MapRoute("Classifieds", "Classifieds", new { controller = "Classifieds", action = "Index" }, new string[] { "Adams.Public.Web.Controllers" });
            routes.MapRoute("ClassifiedsSearch", "Classifieds/Search", new { controller = "Classifieds", action = "Search" }, new string[] { "Adams.Public.Web.Controllers" });
            routes.MapRoute("ClassifiedsPosting", "Classifieds/{id}", new { controller = "Classifieds", action = "Posting", id = "" }, new { id = @"\d+" }, new string[] { "Adams.Public.Web.Controllers" });
            routes.MapRoute("ClassifiedsList", "Classifieds/{type}/{category}", new { controller = "Classifieds", action = "List", category = "" }, new string[] { "Adams.Public.Web.Controllers" });

            routes.MapRoute("Businesses", "Businesses", new { controller = "Businesses", action = "Index" }, new string[] { "Adams.Public.Web.Controllers" });
            routes.MapRoute("BusinessesSearch", "Businesses/Search", new { controller = "Businesses", action = "Search" }, new string[] { "Adams.Public.Web.Controllers" });
            routes.MapRoute("BusinessesBusiness", "Businesses/{id}", new { controller = "Businesses", action = "Business", id = "" }, new { id = @"\d+" }, new string[] { "Adams.Public.Web.Controllers" });
            routes.MapRoute("BusinessesList", "Businesses/{type}/{category}", new { controller = "Businesses", action = "List", category = "" }, new string[] { "Adams.Public.Web.Controllers" });

            routes.MapRoute("Files", "Files/{*url}", new { controller = "Files", action = "Index" });

            routes.MapRoute("Pages", "{*url}", new { controller = "Pages", action = "Index" });
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}